﻿@using System.Web.Script.Serialization
@{
    ViewBag.Title = "EditAttributeValues";
}

<h2>EditAttributeValues</h2>
@{
    
    var model = ViewBag.Model;
    var jsonStr = new HtmlString(new JavaScriptSerializer().Serialize(model));
}

<span data-bind="text:Name"></span>
<label>Value</label>
<input type="text" data-bind="value:Value"/>
<label>Display Order</label>
<input type="text" data-bind="value:DisplayOrder"/>

<input type="button" value="Save" data-bind="click:SaveProductVariantAttributeValue"/>
@section scripts
{
    
    <script>
        var init = @jsonStr;
        
        function ProductVariantAttributeValueModel() {

            var self = this;
            self.ProductVariantAttributeId = ko.observable(init.ProductVariantAttributeId);
            self.Name = ko.observable(init.Name);
            self.Value = ko.observable();
            self.DisplayOrder= ko.observable();
            self.SaveProductVariantAttributeValue = function() {

                $.ajax({
                    url: "/api/ProductVariantAttributeApi/InsertProductVariantAttributeValue",
                    type: 'post',
                    data: ko.toJSON(self),
                    contentType: 'application/json',
                    success: function (result) {

                        if (result.Status == "0") {
                            alert("保存成功");
                            location.href = '/ProductVariantAttributeApi/Edit?productVariantId=' + self.PvId();
                        }
                        else {
                            alert("保存失败：" + result.Msg);
                        }
                    }
                });
            };
        }

        var vm = new ProductVariantAttributeValueModel();
        ko.applyBindings(vm);
    </script>
}
